make%option noyywrap
%{
#include <string.h>
#include <stdio.h>
#include "parser.tab.h"
#include "main.h"
%}

DIGIT [0-9]
IDENT [a-zA-Z_][a-zA-Z_0-9]*
WS    [\n\t\ \r]*
SQUOTE      "'"
DQUOTE      "\""
INSTR       [^\\\"\0]|(\\\")|(\\.)
INCHAR      [^\0\']|(\\\")|(\\\')|(\\.)
BAD         [\'\"\\.:`~!@#$&\[\]|?]

%x ccomment cppcomment str
%%

"/*"            BEGIN(ccomment);
"//"            BEGIN(cppcomment);

<ccomment>[^*\n]*  	 /* non '*' */
<ccomment>"*"+[^*/\n]*   /*  */
<ccomment>"*"+"/"	 BEGIN(INITIAL);

<cppcomment>[^\n]*  	/* do nothing  */
<cppcomment>\n		BEGIN(INITIAL);


{DQUOTE}{INSTR}*{DQUOTE}   { 
				//save strlen(yytext);
				//maybe do in descape
				return TOKEN_STRING_LITERAL; 
			   }
{SQUOTE}{INCHAR}{SQUOTE}   { return TOKEN_CHARACTER_LITERAL; }

{DIGIT}+  {return TOKEN_INTEGER_LITERAL; }

{WS}      

"<="      { return TOKEN_LE; }
">="      { return TOKEN_GE; }
"<"       { return TOKEN_LT; }
">"       { return TOKEN_GT; }
"=="      { return TOKEN_EQ; }
"!="      { return TOKEN_NE; }

"="       { return TOKEN_ASSIGN; }

";"       { return TOKEN_SEMICOLON; }
","       { return TOKEN_COMMA; }

int        { return TOKEN_INTEGER; }
string     { return TOKEN_STRING;  }
char       { return TOKEN_CHAR;    }
boolean    { return TOKEN_BOOLEAN; }
false      { return TOKEN_FALSE; }
true       { return TOKEN_TRUE; }
if         { return   TOKEN_IF            ; }
while      { return   TOKEN_WHILE         ; }
return     { return   TOKEN_RETURN        ; }
else       { return   TOKEN_ELSE          ; }
void       {return    TOKEN_VOID  ; }
print      {return    TOKEN_PRINT ; }

{IDENT}   { return TOKEN_IDENTIFIER; }

"||"      { return   TOKEN_LOGICALOR  ;}
"&&"      { return   TOKEN_LOGICALAND ;}

"("       { return TOKEN_OPENPAREN     ; }
")"       { return TOKEN_CLOSEPAREN    ; }
"{"       { return TOKEN_OPENCURLY     ; }
"}"       { return TOKEN_CLOSECURLY    ; }


"*"       { return TOKEN_STAR     ; }
"/"       { return TOKEN_SLASH    ; }
"%"       { return TOKEN_PERCENT  ; }
"+"       { return TOKEN_PLUS     ; }
"-"       { return TOKEN_MINUS    ; }
"^"       { return TOKEN_CARET    ; }
"++"      { return TOKEN_INCREMENT; }
"--"      { return TOKEN_DECREMENT; }



 /*{CPPCOMMENT}|{CCOMMENT}    {} */
{BAD} {return TOKEN_ERROR; }

%%
